/*
*
*	The Gimme ECMAScript Library by Stephen Stchur
*	"Taking the pain out of Javascript!"
*
*	Copyright (c) Microsoft Corporation.  All rights reserved.
*
*	Description:
*	Gimme Screen Module:		Helper methods dealing with screen geometry (mouse position, scroll position, viewport size, etc...)
*	Gimme Screen Extensions:	g(..) extensions for retrieving DOM element position information
*
*	Requires:
*	gimme.query.js
*	gimme.object.js
*
*/

Gimme.Screen = new function()
{
	this.get_viewport_size = function()
	{
		var size = { width: 0, height: 0 };
		if (typeof window.innerWidth !== 'undefined')
		{
			size = { width: window.innerWidth, height: window.innerHeight };
		}
		else if (typeof document.documentElement !== 'undefined' && typeof document.documentElement.clientWidth !== 'undefined' && document.documentElement.clientWidth !== 0)
		{
			size = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };
		}
		else
		{
			size = { width: document.getElementsByTagName('body')[0].clientWidth, height: document.getElementsByTagName('body')[0].clientHeight };
		}

		return size;
	};

	this.get_mouse_pos = function(_evt)
	{
		_evt = _evt || window.event;

		var cursorPos = { x: 0, y: 0 };

		// Standard way of obtaining cursor position relative to the entire page is via .pageX and .pageY.
		// IE-Mac has .pageX/Y but its value is wrong, so we check for a non-standard .x property (which IE-Mac doesn't have)
		// to ensure that that browser won't fall into this if block.
		if (typeof _evt.pageX !== 'undefined' && typeof _evt.x !== 'undefined')
		{
			cursorPos.x = _evt.pageX;
			cursorPos.y = _evt.pageY;
		}
		else
		{
			// The .clientX/Y properties measure the distance from the mouse cursor to the edges of the browser window.  In order to find the
			// mouse position relative to the entire page, we need to add scroll position to their values.
			// With the exception of Safari, the following is a cross-browser way of obtaining mouse position.  Safari incorrectly give .clientX/Y
			// the same value as .pageX/Y, which is why we need to use .pageX/Y above if it's available
			var scrollPos = this.get_scroll_pos();
			cursorPos.x = _evt.clientX + scrollPos.x;
			cursorPos.y = _evt.clientY + scrollPos.y;
		}

		return cursorPos;
	};

	this.get_scroll_pos = function()
	{
		return Gimme(window).get_scroll_pos();
	};
};

// Gimme Screen Extensions

